package com.oa.android.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.oa.android.R;
import com.oa.android.adapter.BuzouAdapter;
import com.oa.android.adapter.GuocAdapter;
import com.oa.android.entry.Buzou;
import com.oa.android.entry.Guoc;
import com.oa.android.utils.UConstants;
import com.oa.android.utils.Util;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;


/**
 * 步骤
 *
 * @author -zouqh
 */
public class GuocActivity extends Activity implements OnClickListener {

    private ImageView close;
    private TextView title,addEmil,newMulu;
    private ListView listView;
    ProgressDialog dialog;
    private List<Guoc> emilList;
    private int page = 1;
    private int pageSize = 12;
    private int allPage = 0;
    private GuocAdapter adapter;


    private String dri="";
    private String filetype;
    private String wkfid;
    private String name;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.buzou_activity);
        close = (ImageView) findViewById(R.id.close);
        title = (TextView) findViewById(R.id.title_text);
        addEmil= (TextView) findViewById(R.id.ritgh_text);
        newMulu= (TextView) findViewById(R.id.new_file);
        listView = (ListView) findViewById(R.id.listView);
        wkfid=getIntent().getStringExtra("id");
        name=getIntent().getStringExtra("name");
        title.setText(name+"");

        close.setOnClickListener(this);
        addEmil.setOnClickListener(this);
        emilList = new ArrayList<>();

        adapter = new GuocAdapter(this, emilList);
        listView.setAdapter(adapter);
        getDate();


    }



    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        Intent intent;
        switch (v.getId()) {
            case R.id.close:
                finish();
                break;




            default:
                break;
        }
    }






    //获取文件列表
    private void getDate() {
        dialog = ProgressDialog.show(this, null, "加载中...", true, false);
        RequestParams params = new RequestParams(UConstants.GET_WORK_GC);
        params.addBodyParameter("LKind", "OA");
        params.addBodyParameter("EmpId", UConstants.EmpId);
        params.addBodyParameter("ID", wkfid);

        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Util.printLog("getMerchants------------onSuccess-----", result);
                if (result.length() > 0) {
                    try {
                        JSONObject object = new JSONObject(result);
                        boolean success = object.getBoolean("success");
//                        String msg = object.getString("msg");
                        if (success) {
                            Gson gson = new Gson();
                            Type lt = new TypeToken<List<Guoc>>() {
                            }.getType();
                            List<Guoc> list = gson.fromJson(object.getString("rows").toString(), lt);
//                            getJson(object.getString("rows").toString());
                            if (list != null && list.size() > 0) {
//								adapter = new CurstorAdapter(OlneSelectActivity.this, crutorJluList);
//								listView.setAdapter(adapter);
//                                title.setText(list.get(0).getWFNAME());
                                emilList.addAll(list);
                                adapter.notifyDataSetChanged();


                            } else {
                                Toast.makeText(x.app(), "暂无过程！", Toast.LENGTH_LONG).show();
                            }

                        } else {
                            Toast.makeText(x.app(), "暂无过程！", Toast.LENGTH_LONG).show();
                        }
//                        Toast.makeText(x.app(), msg, Toast.LENGTH_LONG).show();
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                dialog.dismiss();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                Util.printLog("getMerchants------------onError-----", ex.getMessage() + "");

                Toast.makeText(x.app(), "获取数据失败！", Toast.LENGTH_LONG).show();
                dialog.dismiss();
            }

            @Override
            public void onCancelled(CancelledException cex) {

                Toast.makeText(x.app(), "cancelled", Toast.LENGTH_LONG).show();
                Util.printLog("getMerchants------------onCancelled-----", cex.getMessage() + "");
                dialog.dismiss();
            }

            @Override
            public void onFinished() {

            }
        });
    }







}
